import yaml
import os

BASE_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
YAML_PATH = os.path.join(BASE_PATH,"test_cfg")

def get_first_file(file_path,suffix=".yaml"):
    files = os.walk(file_path)
    try:
        files = next(files)[2]#获取当前目录下的非目录文件,os.walk()返回一个迭代器
    except Exception:
        return None
    else:
        for f in files:
            if f.endswith(suffix):
                return f

def read_yaml(yaml_file):
    with open(yaml_file) as f:
        cfg = yaml.load(f.read())
    return cfg

def get_yaml_file():
    yaml_file = get_first_file(YAML_PATH)
    yaml_file = os.path.join(YAML_PATH, yaml_file)
    return yaml_file
